//
//  OrderTableViewCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/21.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "OrderTableViewCell.h"

@interface OrderTableViewCell ()

@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * buyTypeLabel;
@property (nonatomic, weak)UILabel * floatMoneyLabel;
@property (nonatomic, weak)UILabel * showBuyTypeLabel;
@property (nonatomic, weak)UILabel * buyMoneyLabel;
@property (nonatomic, weak)UILabel * floatLabel;
@property (nonatomic, weak)UIView * lineView;

@property (nonatomic, strong)NSArray * fiveArray;
@property (nonatomic, strong)NSArray * threeArray;
@property (nonatomic, strong)NSArray * twoArray;

@end

@implementation OrderTableViewCell




- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    self.fiveArray = @[@"EURUSDapp",@"NZDUSDapp",@"EURCADapp",@"USDCADapp",@"EURNZDapp",@"AUDNZDapp",@"AUDUSDapp",@"AUDCADapp",@"GBPCHFapp",@"EURAUDapp",@"EURGBPapp",@"CADCHFapp",@"GBPAUDapp",@"EURCHFapp",@"USDCHFapp",@"GBPCADapp",@"GBPNZDapp",@"AUDCHFapp",@"GBPUSDapp"];
    self.threeArray = @[@"XAGUSDapp",@"GBPJPYapp",@"AUDJPYapp",@"USDJPYapp",@"EURJPYapp",@"CADJPYapp",@"NZDJPYapp"];
    self.twoArray = @[@"XAUUSDapp"];
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    nameLabel.textColor = ColorWithRGB(0xffffff);
    nameLabel.textAlignment = NSTextAlignmentLeft;
//    nameLabel.text = @"USDCNH";
    
    self.nameLabel = nameLabel;
    
    [self addSubview:self.nameLabel];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(8 * SCREENH6);
    }];
    
    
    UILabel * positionId = [UILabel new];
    
    positionId.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    positionId.textColor = ColorWithRGB(0xffffff);
    positionId.textAlignment = NSTextAlignmentLeft;
    positionId.hidden = YES;
    
    self.positionId = positionId;
    
    [self addSubview:self.positionId];
    
    [self.positionId mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel.mas_trailing);
        make.top.mas_equalTo(self.nameLabel);
    }];
    
    UILabel * buyTypeLabel = [UILabel new];
    
    buyTypeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    buyTypeLabel.textAlignment = NSTextAlignmentCenter;
    buyTypeLabel.textColor = RED_COLOR;
//    buyTypeLabel.text = @"买涨";
    
    self.buyTypeLabel = buyTypeLabel;
    
    [self addSubview:self.buyTypeLabel];
    
    [self.buyTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.nameLabel);
    }];
    
    
    UILabel * floatMoneyLabel = [UILabel new];
    
    floatMoneyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    floatMoneyLabel.textAlignment = NSTextAlignmentRight;
    floatMoneyLabel.textColor = RED_COLOR;
//    floatMoneyLabel.text = @"+$1.88";
    
    self.floatMoneyLabel = floatMoneyLabel;
    
    [self addSubview:self.floatMoneyLabel];
    
    [self.floatMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(- 15 * SCREENH6);
        make.centerY.mas_equalTo(self.buyTypeLabel);
    }];
    
    
    UILabel * showBuyTypeLabel = [UILabel new];
    
    showBuyTypeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    showBuyTypeLabel.textColor = ColorWithRGB(0xfa6a6a6);
    showBuyTypeLabel.textAlignment = NSTextAlignmentLeft;
//    showBuyTypeLabel.text = @"成交价";
    
    self.showBuyTypeLabel = showBuyTypeLabel;
    
    [self addSubview:self.showBuyTypeLabel];
    
    [self.showBuyTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(5 * SCREENH6);
    }];

    
    UILabel * buyMoneyLabel = [UILabel new];
    
    buyMoneyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    buyMoneyLabel.textAlignment = NSTextAlignmentCenter;
    buyMoneyLabel.textColor = ColorWithRGB(0xfa6a6a6);
//    buyMoneyLabel.text = @"6.76535";
    
    self.buyMoneyLabel = buyMoneyLabel;
    
    [self addSubview:self.buyMoneyLabel];
    
    [self.buyMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.showBuyTypeLabel);
    }];
    
    
    UILabel * floatLabel = [UILabel new];
    
    floatLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    floatLabel.textAlignment = NSTextAlignmentRight;
    floatLabel.textColor = ColorWithRGB(0xfa6a6a6);
    floatLabel.text = @"浮动盈亏";
    
    self.floatLabel = floatLabel;
    
    [self addSubview:self.floatLabel];
    
    [self.floatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.floatMoneyLabel);
        make.centerY.mas_equalTo(self.buyMoneyLabel);
    }];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = [UIColor whiteColor];
    lineView.alpha = 0.1;
    
    self.lineView = lineView;
    
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1 * SCREENH6);
    }];

}




- (void)setModel:(positionsListModel *)model{
    
    _model = model;
    
    /*
     @property (nonatomic, weak)UILabel * nameLabel;
     @property (nonatomic, weak)UILabel * buyTypeLabel;
     @property (nonatomic, weak)UILabel * floatMoneyLabel;
     @property (nonatomic, weak)UILabel * showBuyTypeLabel;
     @property (nonatomic, weak)UILabel * buyMoneyLabel;
     @property (nonatomic, weak)UILabel * floatLabel;
     */
    
    self.nameLabel.text = [NSString stringWithFormat:@"%@",model.symbol];
    
    
    BOOL isFivebool = [self.fiveArray containsObject:self.nameLabel.text];
    BOOL isThreebool = [self.threeArray containsObject:self.nameLabel.text];
    BOOL isTwobool = [self.twoArray containsObject:self.nameLabel.text];
    
    float openPrice = [model.openPrice floatValue];
    
    if (isFivebool) {
        
        self.buyMoneyLabel.text = [NSString stringWithFormat:@"%.5f",openPrice];
    }
    
    if (isThreebool) {
        
       self.buyMoneyLabel.text = [NSString stringWithFormat:@"%.3f",openPrice];
    }
    
    if (isTwobool) {
        
        self.buyMoneyLabel.text = [NSString stringWithFormat:@"%.2f",openPrice];
    }
    
//    self.buyMoneyLabel.text = [NSString stringWithFormat:@"%@",model.openPrice];
    
    float floatCount = [model.pnl floatValue];
    
    if (floatCount > 0) {
        self.floatMoneyLabel.text = [NSString stringWithFormat:@"+$%.2f",floatCount];
        self.floatMoneyLabel.textColor = RED_COLOR;
    }else{
        NSString * floatString = [NSString stringWithFormat:@"%.2f",floatCount];
        floatString = [floatString substringFromIndex:1];
        
        self.floatMoneyLabel.text = [NSString stringWithFormat:@"-$%@",floatString];
        self.floatMoneyLabel.textColor = GREEN_COLOR;
    }
    
//    self.floatMoneyLabel.text = [NSString stringWithFormat:@"%@",model.pnl];
    self.positionId.text = [NSString stringWithFormat:@"%@",model.positionId];
    
    NSString * orderDirection = [NSString stringWithFormat:@"%@",model.orderDirection];
    
    if ([orderDirection isEqualToString:@"Buy"]) {
        
        self.buyTypeLabel.textColor = RED_COLOR;
        
        self.buyTypeLabel.text = @"买";
//        self.showBuyTypeLabel.text = @"买涨价";
        
    }else{
        
        self.buyTypeLabel.textColor = GREEN_COLOR;
        
        self.buyTypeLabel.text = @"卖";
//        self.showBuyTypeLabel.text = @"买跌价";
        
    }
    
    self.showBuyTypeLabel.text = [NSString stringWithFormat:@"%@手",model.volume];
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
